/*
 * Jiri Cigler
 * ciglej1@fel.cvut.cz 
 *
 * Copyright (C) 2007 Jirka Cigler <ciglej1@fel.cvut.cz>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 */ 


#ifndef __SCHEDULER_HH__
#define __SCHEDULER_HH__

#include "../src/timer.hh"
#include "../src/types.hh"

#include "gecode/kernel.hh"
//#include "gecode/int/minimodel.hh"
#include "gecode/kernel.hh"
#include "gecode/int.hh"
#include "gecode/search.hh"
#include "gecode/minimodel.hh"
#include "gecode/cpltset.hh"
/**
 * \file shopSolver.hh
 * \author Jiri Cigler
 * \brief Declaration of ShopSolver
 * \see ShopSolver
 */

/**
 * \namespace Gecode 
 * \brief Toplevel namespace for constraint programming
 * more info: http://www.gecode.org/
 */
using namespace Gecode;

/**
 * \namespace std 
 * \brief Namespace for using STL 
 * more info: http://www.cppreference.com/
 */
using namespace std;


/**
 *\brief Object which is able to solve scheduling problem
 */
class ShopSolver :  public Space {

	protected:

		///Number of jobs
		int jobs;
		///Number of tasks in each job       
		int tasksInJob;
		///Number of processors
		int machines;
		///Domain of starting times
		IntVarArray q;
	public:
		/**
		 * \brief Constructor of class
		 * \param jobs Number of jobs
		 * \param tasksInJob Number of tasks in each job
		 * \param processors Number of processors
		 * \param maxTime Upper limit of domain
		 * \param taskList List of tasks with precedence
		 * constrains between them.
		 */
		ShopSolver(  int jobs, int tasksInJob, int processors, unsigned int maxTime, vector<Task> & taskList);
		/**
		 * \brief Destructor
		 */
		~ShopSolver();

		ShopSolver(bool share, ShopSolver& iShopSolver) : Space(share,iShopSolver) {
			q.update(this, share, iShopSolver.q);
			jobs = iShopSolver.jobs;
			tasksInJob= iShopSolver.tasksInJob;
			machines= iShopSolver.machines;
		}
		/**
		 * \brief Write result to r
		 * \param r Result will be written to this variable
		 * \param sortTable vector with indexes for correct
		 * reconstruction of input matrix
		 * \param verbose if true print elements to console
		 */
		void result(unsigned int ** & r, vector<SortTableElement> &sortTable ,bool verbose);

		void print(void);
		/**
		 * \brief Copy constructor
		 */
		Space*  copy(bool share) {return new ShopSolver(share,*this); }
		/**
		 * \brief Add constrain during finding solution
		 */
		void constrain(ShopSolver* iShopSolver);

	private:
		explicit ShopSolver(ShopSolver& iShopSolver);
		/**
		 *\brief Create constraints, branch
		 */
		void solve(vector<Task> &taskList);
};


#endif

